//
//  WHZSportTrackingLine.m
//  WHZGuDong
//
//  Created by whz on 16/11/10.
//  Copyright © 2016年 whz. All rights reserved.
//

#import "WHZSportTrackingLine.h"

@implementation WHZSportTrackingLine

- (instancetype)initWithStartLocation:(CLLocation *)startLocation endLocation:(CLLocation *)endLocation {

    if (self = [super init]) {
        
        _startLocation = startLocation;
        _endLocation = endLocation;
    }
    return self;
}

- (WHZSportPolyline *)polyline {
    
    CLLocationCoordinate2D coords[2];
    
    coords[0] = _startLocation.coordinate;
    coords[1] = _endLocation.coordinate;
    
    // MARK: - 临时 设置放大比例因子
    CGFloat factor = 8;
    CGFloat red = factor * self.speed / 255.0;
    UIColor *color = [UIColor colorWithRed:red green:1 blue:0 alpha:1];

    // MARK: - 测试两点间运动数据
    NSLog(@"速度 %f -- 时间 %f -- 距离 %f",self.speed, self.time, self.distance);
    
    return [WHZSportPolyline polylineWithCoordinates:coords count:2 color:color];
}

#pragma mark - 设置数据 get方法 懒加载
- (CLLocationSpeed)speed {

    // MARK: - 速度的计算
    // m / s => km / hour
    // m / s => 1000 * m / 3600 * s
    // (3600 * m) / (s * 1000) => km / hour
    return (_startLocation.speed + _endLocation.speed) * 0.5 * 3.6;
}
- (NSTimeInterval)time {

    return [_endLocation.timestamp timeIntervalSinceDate:_startLocation.timestamp];
}
- (double)distance {

    return [_endLocation distanceFromLocation:_startLocation];
}

@end
